<template>
  <div>
    <h1>新年倒计时</h1>
    <p>{{ countdown }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      countdown: 0,
    };
  },
  mounted() {
    this.startCountdown();
  },
  methods: {
    startCountdown() {
      const targetDate = new Date("2023-01-01");
      const currentDate = new Date();

      const timeDifference = targetDate.getTime() - currentDate.getTime();
      const secondsDifference = Math.floor(timeDifference / 1000);

      this.countdown = secondsDifference;
      setInterval(() => {
        this.countdown--;
      }, 1000);
    },
  },
};
</script>

